package club.yuit.desktop.ui;

import com.formdev.flatlaf.extras.FlatSVGIcon;

import javax.swing.*;
import javax.swing.plaf.LayerUI;
import java.awt.*;
import java.awt.geom.Ellipse2D;

/**
 * @author: yuit
 * @date: 2023/12/11 16:52
 */
public class FloatingButtonUI  extends LayerUI<JPanel> {

    private int size;
    private Shape shape;

    private int position;
    private Image image;

    public FloatingButtonUI(int size,int position) {
        this.size = size;
        this.position = position;
        FlatSVGIcon icon = new  FlatSVGIcon("imgs/send.svg");
        image = icon.getImage();

    }

    @Override
    public void paint(Graphics graphics, JComponent c) {
        super.paint(graphics, c);
        Graphics2D g = (Graphics2D) graphics.create();

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        int x = c.getWidth()-size-15;
        int y = c.getHeight()-size-15;

        shape = new Ellipse2D.Double(x,y,size,size);
        g.setColor(Color.BLUE);
        g.fill(shape);
        g.setColor(Color.WHITE);
        int iconSize = size/2;
        int iconX = x+iconSize/2;
        int iconY = y+iconSize/2;
        g.drawImage(image,iconX,iconY,iconSize,iconSize,null);
        g.dispose();
    }
}
